﻿//========================================================= 
/**@file AndroidPCSC_Installer.h
 * @brief Android下PCSC CCID设备驱动
 * 
 * @date 2018-07-28   09:20:10
 * @author Zhyioo 
 * @version 1.0
 */ 
//--------------------------------------------------------- 
#ifndef _LIBZHOUYB_ANDROIDPCSC_INSTALLER_H_
#define _LIBZHOUYB_ANDROIDPCSC_INSTALLER_H_
//--------------------------------------------------------- 
#include "PCSC_Installer.h"

#include "../../tools/IconvAppConvert.h"
using zhou_yb::application::tools::PbocTlvConvert;

#include "../device/JniCmdDriver.h"
//--------------------------------------------------------- 
namespace zhou_yb {
namespace application {
namespace driver {
//--------------------------------------------------------- 
/// Android下PCSC装载器
class AndroidPCSC_Installer
{
protected:
    AndroidPCSC_Installer() {}
public:
    static void Install(CommandRunner& runner, const char* devId = NULL)
    {
        PCSC_Installer installer(runner);

        const char DEV_ID[] = "DEV";
        if(devId == NULL)
        {
            devId = DEV_ID;
        }
        installer.InstallDEV<JniIccInvokeCmdDriver>(devId);
        installer.Install(devId);

        CommandSetter setter(runner);
        setter.Registe(runner.Get(devId).Get("JniEnvCreate;JniEnvDispose"));

        CommandRunnerActuator actuator(runner);
        string scriptCmdName = "Script.";
        scriptCmdName += devId;
        scriptCmdName += ".OpenBindCMD";
        Ref<ComplexCommand> complexCmd = CommandInstaller::LookUp(runner, scriptCmdName.c_str());
        if(!complexCmd.IsNull())
        {
            complexCmd->OnCommand(actuator.Arg(), actuator.Result());
            actuator.Reset();
        }
        actuator.Set(devId).Run("ITransceiveTrans", true).Run("Select_ITransceiveTrans").Reset();

        pointer p = reinterpret_cast<pointer>(PbocTlvConvert::GbkToUTF8);
        actuator.Arg("TlvConvert", ArgConvert::ToString(p));
        actuator["PBOC"].Call("SetTlvConvert").Reset();
    }
};
//--------------------------------------------------------- 
} // nemespace driver
} // namespace application
} // namespace zhou_yb
//--------------------------------------------------------- 
#endif // _LIBZHOUYB_ANDROIDPCSC_INSTALLER_H_
//========================================================= 